<?php
namespace app_admin\controllers;

use YII;
use yii\web\Controller;

class LoginController extends Controller
{
    public $layout = false;

    public function actionIndex()
    {
        if (YII::$app->request->method == "POST") {
            $account = isset($_POST['account']) ? $_POST['account'] : '';
            $pwd = isset($_POST['pwd']) ? $_POST['pwd'] : '';
            $result = array("flag" => false, "msg" => "");
            if (empty($account) || empty($pwd)) {
                $result['msg'] = "请输入账号或密码";
            } else {
                if ($account == "admin" && $pwd == "1231500") {
                    $result['flag'] = true;
                    YII::$app->session->set("user","admin");
                } else {
                    $result['msg'] = "账号或密码错误";
                }
            }
            echo json_encode($result);
            exit;
        }
        return $this->render('index.html', array());
    }
}
